<template lang="jade">
	div.return-bar
		i.iconfont(@click="back()") &#xe668;
		积分记录
	div.shoping-page.detail_top(v-infinite-scroll="down()", infinite-scroll-disabled="busy", infinite-scroll-distance="10")

		div.filter
			flexbox
				flexbox-item(:span='4', style="position:relative;height:0.85rem;")

					input(type="text",v-model="star_time", placeholder="请选择开始日期")
					input(type="date",v-model="date")

					//calendar(:value.sync="edate", :weeks-list="weeksList")
				flexbox-item(:span='1',style="text-align:center;color:#999") ―
				flexbox-item(:span='4', style="position:relative;height:0.85rem;")
					input(type="text",v-model="end_time", placeholder="请选择结束日期")
					input(type="date",v-model="date1")

					//calendar(:value.sync="edate", :weeks-list="weeksList")
				flexbox-item(style="text-align:right;")
					input.p_btn(type="button", value="筛选", @click="search()")

		div(v-for=" item in items ")
			dl.money_record.point_record(v-for=" (index, a) in item ")
				dt {{index}}
				dd( v-for=" (index, b) in a ")
					span.date {{b.day}}
						br
						span {{b.month}}
					span.content
						b(v-bind:class="{ 'green': b.symbol == '+', 'red': b.symbol == '-' }") {{b.symbol}}{{b.integral}}
						em {{b.type}}
					span.extra
						strong {{b.current}}
						em 当前积分

</template>

<script>
import '../../assets/sass/shopping.scss'
import {c_integralLog} from '../../config/api'
import {Calendar, Group, Loading, Flexbox, FlexboxItem} from 'vux'

var date = Date;
var date1 = Date;
export default{
	data(){
		return{
			items:[],
			page:1,
			star_time:'',
			//sdate:date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate(),
			end_time:'',
			weeksList:['日', '一', '二', '三', '四', '五', '六 ']
		}
	},
	components: {
		Flexbox,
		FlexboxItem,
		Loading,
		Group,
		Calendar
	},
	watch: {
		date: function (val) {
			this.star_time = this.date
		},
		date1: function (val) {
			this.end_time = this.date1
		}
	},
	methods: {
	    back(){
	      window.history.back();
	    },
	    setDate(key){
	    	console.log(key)
	    	//this.star_time = date.getFullYear() +'-'+ date.getMonth() + '-'+ date.getDate()
	    },

		down: function() {
			if(this.busy == true || this.items == ''){
				return false;
			} 
			this.busy = true;
			this.fetch(++this.page)
		},
		search(){
			if(this.star_time=="" || this.end_time==""){
				alert("请选择日期");
				return false;
			}
			this.page = 1;
			this.items = [];
			this.busy = true;
			this.fetch(1)
		},

		fetch: function (page) {
			this.$http({url: c_integralLog+'&number=10&star_time='+this.star_time+'&end_time='+this.end_time+'&page='+this.page, method: 'GET'}).then(function (response) {
				var obj = response.data;
				
				if(obj.status){
					this.items = this.items.concat(response.data.list);
					this.busy = false;
				}
				else{
					return;
				}
			});
		}

	},
	route:{
		activate( transition ){
			transition.next();
			this.fetch(1);
		}
	}
}

</script>
